// note: import flabuffers with your desired import method
import { flatbuffers } from "flatbuffers";
import { MyGame } from "./monster";
export default  function read(bytes) {
  // let bytes = /* the data you just read, in an object of type "Uint8Array" */
  let buf = new flatbuffers.ByteBuffer(bytes);
  // Get an accessor to the root object inside the buffer.
  let monster = MyGame.Sample.Monster.getRootAsMonster(buf);
  let pos = monster.pos();
  let x = pos.x();
  let y = pos.y();
  let z = pos.z();
  let invLength = monster.inventoryLength();
  let thirdItem = monster.inventory(2);

  let weaponsLength = monster.weaponsLength();
  let secondWeaponName = monster.weapons(1).name();
  let secondWeaponDamage = monster.weapons(1).damage();

  console.log(secondWeaponName)
  console.log(secondWeaponDamage)

  let unionType = monster.equippedType();
  if (unionType == MyGame.Sample.Equipment.Weapon) {
    let weapon_name = monster.equipped(new MyGame.Sample.Weapon()).name(); // 'Axe'
    let weapon_damage = monster.equipped(new MyGame.Sample.Weapon()).damage(); // 5
    console.log(weapon_name)
    console.log(weapon_damage)
  }
}
